﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// MyDataGrid 控件与属性编辑器的交互
    /// </summary>
    public class GetMyDataGridProperty : GetCtrlUIProperty
    {
        public GetMyDataGridProperty(MyDataGrid myDataGrid)
            : base(myDataGrid)
        {
            _myDataGrid = myDataGrid;
        }

        private MyDataGrid _myDataGrid = null;

        [Browsable(false)]
        public override Medicalsystem.MCP.FormDesigner.Common.EBorderStyle BorderStyleZ
        {
            get
            {
                return base.BorderStyleZ;
            }
            set
            {
                base.BorderStyleZ = value;
            }
        }

        [Browsable(false)]
        public override string ShowText
        {
            get
            {
                return base.ShowText;
            }
            set
            {
                base.ShowText = value;
            }
        }

        //[Browsable(false)]
        //public override Color ForeColor
        //{
        //    get
        //    {
        //        return base.ForeColor;
        //    }
        //    set
        //    {
        //        base.ForeColor = value;
        //    }
        //}

        /// <summary>
        /// 列调整模式
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("列调整模式")]
        [Description("确定可见列的自动调整大小模式")]
        public DataGridViewAutoSizeColumnsMode AutoSizeColumnsMode
        {
            get
            {
                return _myDataGrid.AutoSizeColumnsMode;
            }
            set
            {
                _myDataGrid.AutoSizeColumnsMode = value;
            }
        }

        [CategoryAttribute("外观")]
        [Description("背景颜色")]
        [ShowChinese("背景颜色")]
        public override Color BackColor
        {
            get
            {
                return _myDataGrid.BackgroundColor;
            }
            set
            {
                _myDataGrid.BackgroundColor = value;
            }
        }

        [CategoryAttribute("外观")]
        [ShowChinese("是否显示行标")]
        [Description("指示是否包含行标题的列")]
        public bool RowHeadersVisible
        {
            get
            {
                return _myDataGrid.RowHeadersVisible;
            }
            set
            {
                _myDataGrid.RowHeadersVisible = value;
            }
        }

        /// <summary>
        /// 控件列
        /// </summary>
        [CategoryAttribute("杂项")]
        [ShowChinese("控件列")]
        [Description("Columns")]
        [EditorAttribute(typeof(ContentEditorModal), typeof(System.Drawing.Design.UITypeEditor)),
TypeConverterAttribute(typeof(ContentConverter))]
        public List<MyDataGridColumn> MyColumns
        {
            get
            {
                return _myDataGrid.MyColumns;
            }
            set
            {
                _myDataGrid.MyColumns = value;
            }
        }

        public override object ShowEditor(Type propertyType, string propertyName, object value)
        {
            if (propertyType.Equals(typeof(List<MyDataGridColumn>)))
            {
                using (Form_MyDataGridColumnsSet F = new Form_MyDataGridColumnsSet())
                {
                    F.MyColumns = value as List<MyDataGridColumn>;
                    if (F.ShowDialog() == DialogResult.OK)
                    {
                        value = F.MyColumns;
                    }
                }
            }
            else
            {
                value = base.ShowEditor(propertyType, propertyName, value);
            }

            return value;
        }

        public override string DescriptorContext(Type propertyType, string propertyName, object value)
        {
            string context = string.Empty;

            if (propertyType.Equals(typeof(List<MyDataGridColumn>)))
            {
                context = string.Format("Columns[{0}]", ((List<MyDataGridColumn>)value).Count.ToString());
            }
            else
            {
                context = base.DescriptorContext(propertyType, propertyName, value);
            }

            return context;
        }
    }
}